# -*- coding: utf-8 -*-

from celery import Celery, platforms
from kombu import Queue, Exchange
from config.etc import CELERY_BROKER_URL

celery_app = Celery()


class CeleryConfig:
    CELERY_ENABLE_UTC = True
    CELERY_TIMEZONE = 'Asian/Shanghai'
    CELERY_QUEUES = (
        Queue('default', Exchange('default'), routing_key='default'),
        Queue('cmsupdateall', Exchange('app'), routing_key='app.cms.updateall'),
    )

    CELERY_ROUTES = ({'tasks.cms.update_all': {
        'queue': 'cmsupdateall',
        'routing_key': 'app.cms.updateall'
    }}, )

    CELERY_DEFAULT_QUEUE = 'default'
    CELERY_DEFAULT_EXCHANGE_TYPE = 'direct'
    CELERY_DEFAULT_ROUTING_KEY = 'default'

    CELERY_IMPORTS = (
        'tasks.cms',
    )
    BROKER_URL = CELERY_BROKER_URL
    CELERY_RESULT_BACKEND = "amqp"

    platforms.C_FORCE_ROOT = True

    # rabbitmq 热备
    CELERY_QUEUE_HA_POLICY = 'all'

celery_app.config_from_object(CeleryConfig)
# or using the fully qualified name of the object:
#   app.config_from_object('module:Config')
